package quick.start.ui;

import quick.start.core.ApplicationBase;
import quick.start.core.async.IWaitting;
import quick.start.core.async.Waitting;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;

public abstract class BaseActivity extends FragmentActivity implements IWaitting {

	private Waitting mWaitting;
	
    /**
     * 控件初始化
     */
	protected abstract void initView();
	
    /**
     * 基础构建前的动作，需要时进行重载
     * 
     * @param savedInstanceState bundle
     */
	protected abstract void onBeforeCreate(Bundle savedInstanceState);
	
    /**
     * 基础构建动作，常用于设置视图等相关动作
     * 
     * @param savedInstanceState bundle
     */
	protected abstract void onBaseCreate(Bundle savedInstanceState);
	
    /**
     * 控件初始化后相关动作，可以初始化需要的Handler
     * 
     * @param savedInstanceStat bundle
     */
	protected abstract void onAfterCreate(Bundle savedInstanceState);

    /**
     * 成员初始化
     */
	protected abstract void setFieldValue();
	
	public void showExitDialog(){
        AlertDialog dialog = new AlertDialog.Builder(this).setTitle("确定要退出程序吗?").setNeutralButton("确定", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                ((ApplicationBase) ApplicationBase.getApplication()).exit();
            }
        }).setNegativeButton("取消", null).create();
        dialog.show();
	}
	
	@Override
	public Waitting getWatting() {
		return mWaitting;
	}

	@Override
	public Waitting initWaitting() {
		return new Waitting(this);
	}

	@Override
	public Context getWaittingContext() {
		return this;
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		ApplicationBase app = (ApplicationBase)getApplication();
		app.registerActivity(this);
		mWaitting = initWaitting();
		onBeforeCreate(savedInstanceState);
		onBaseCreate(savedInstanceState);
		initView();
		setFieldValue();
		onAfterCreate(savedInstanceState);
	}

	
}
